<template>

</template>


<script>
  export default {
  }
</script>

<!--
<script>
  let defaultclient;
  function mqtt_publish(topic , message){
    console.log('mqtt send to \ntopic:' + topic + ' \nmsg:' +message.toString())
    defaultclient.publish(topic, message)
  }

  function mqtt_subscribe(topic){
    defaultclient.subscribe(topic, function (err) {
      if (!err) {
        // defaultclient.publish(topic, 'Hello mqtt' + topic)
      }
    })
  }

  function mqtt_init(){
    let sss = this;
    let mqtt = require('mqtt')

    let options = {
      username: 'bang',
      password: 'qq2711524',

    };

    let client  = mqtt.connect('mqtt://127.0.0.1:8083/mqtt',options)
    defaultclient = client
    client.on('connect', function () {
      client.subscribe('presence', function (err) {
        if (!err) {
          client.publish('presence', 'Hello mqtt')
        }
      })
    })

    client.on('offline', function () {

    })


    client.on('message', function (topic, message) {
      // alert('mqtt recive from \ntopic:' + topic + ' \nmsg:' +message.toString())
      let a = hextoString('46474849');
      let b = stringtoHex('ABCD');
      let c = buffer2hex(message);
      console.log('mqtt recive from topic:' + topic + ' hex:' +c +' msg:' +message.toString())
      // Toast(message.toString());

      let jsonObj = null
      try {
        jsonObj = JSON.parse(message.toString());
      }catch (e) {

      }
      sss.deviceList = jsonObj
    })
  }
  export default {
    mqtt_init,
    defaultclient,
    mqtt_publish,
    mqtt_subscribe
  }
</script>
-->

<style scoped>

</style>
